var wapjs = {
    urlconfig : {  //url配置
        "login":"http://10.8.230.128:8080/view/login" //登陆?mobile=11111&password=22222
    },
    init : function () {   //初始任务
        this.bindEvent();  //绑定事件
    },
    bindEvent : function(){   //绑定事件
        var self  = this;
        $(".loading").on("click", function () {
            self.tank("load");
        });
        $(".kongBnt").on("click", function () {
            self.tank("load");
        });
        $(".zhangBnt").on("click", function () {
            self.tank("reg");
        });
        $(".alertBnt").on("click", function () {
            $(".alert").hide();
            $(".warp_tip").hide();
        });
        $(".confrimBnt2").on("click", function () {
            $(".confrim").hide();
            $(".warp_tip").hide();
        });
        $(".loginBnt").on("touchstart",function(){
            var mobile = $(".loadMobile").val();
            var password = $(".loadPwd").val();
            if(!self.visPhone(mobile)){
                alert("您输入的手机号码有误，请重新输入！");
                return;
            }
            var data = {mobile:mobile,password:password};
            self.doAjax(self.urlconfig.login,function(){
                $(".load").hide();
                $(".warp_tip").hide();
                var html = "<span class='fl bg2_c2_1_span1'>我的手机号："+mobile+"</span><span class='fr bg2_c2_1_span2'>退出</span>";
                $(".loading").html(html);
            },data);
        })
    },
    doAjax : function(url,callback,data){   //数据交互
        var ajaxObj = {
            url : url,
            dataType : "JSON",
            type : "GET",
            success : function(res){
                if(res.retCode === "000"){
                    callback();
                }else{
                    alert(res.retMsg);
                }
            },
            error:function(){
                alert("请求超时，请重新再试!");
            }
        };
        if(data)
            ajaxObj.data = data;
        $.ajax(ajaxObj);
    },
    visPhone : function (str) {  //校验手机号码
        var patrn = /(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/;
        if (!patrn.exec(str)){
            return false;
        } return true;
    },
    tank : function(type){   //弹框样式
        var screenWidth = $(window).width();
        var screenHeight = $(window).height(); //当前浏览器窗口的 宽高
        var scrolltop = $(document).scrollTop();//获取当前窗口距离页面顶部高度
        var objLeft = "";
        var objTop = "";
        var thisDiv = "";
        $(".warp_tip").show();
        if(type == "alert"){
            $(".warp_tip div").hide();
            thisDiv = $(".alert");
            $(".alert").show();
            $(".alert div").show();
        }else if(type == "confrim"){
            $(".warp_tip div").hide();
            thisDiv = $(".confrim");
            $(".confrim").show();
            $(".confrim div").show();
        }else if(type == "load"){
            $(".warp_tip div").hide();
            thisDiv = $(".load");
            $(".load").show();
            $(".load div").show();
        }else if(type == "reg"){
            $(".warp_tip div").hide();
            thisDiv = $(".reg");
            $(".reg").show();
            $(".reg div").show();
        }
        objLeft = (screenWidth - thisDiv.width())/2;
        objTop = (screenHeight - thisDiv.height())/2 + scrolltop;
        thisDiv.css({"top":objTop+"px","left":objLeft+"px"});
    }
};
wapjs.init();

/*
$(".kongBnt").on("click", function () {
    tank("alert");
});
$(".zhangBnt").on("click", function () {
    tank("confrim");
});

function tank(type){
    var screenWidth = $(window).width();
    var screenHeight = $(window).height(); //当前浏览器窗口的 宽高
    var scrolltop = $(document).scrollTop();//获取当前窗口距离页面顶部高度
    var objLeft = "";
    var objTop = "";
    var thisDiv = "";
    $(".warp_tip").show();
    if(type == "alert"){
        $(".warp_tip div").hide();
        thisDiv = $(".alert");
        $(".alert").show();
        $(".alert div").show();
    }else if(type == "confrim"){
        $(".warp_tip div").hide();
        thisDiv = $(".confrim");
        $(".confrim").show();
        $(".confrim div").show();
    }else if(type == "load"){
        $(".warp_tip div").hide();
        thisDiv = $(".load");
        $(".load").show();
        $(".load div").show();
    }else if(type == "reg"){
        $(".warp_tip div").hide();
        thisDiv = $(".reg");
        $(".reg").show();
        $(".reg div").show();
    }
    objLeft = (screenWidth - thisDiv.width())/2;
    objTop = (screenHeight - thisDiv.height())/2 + scrolltop;
    thisDiv.css({"top":objTop+"px","left":objLeft+"px"});
}*/
